﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace zwWitLink.Helper
{
    class HttpHelper
    {
        //public static string Post(string filepath,string remoteUrl)
        //{
        //    FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);

        //     byte[] byteFile = new byte[fs.Length];

        //    fs.Read(byteFile, 0, Convert.ToInt32(fs.Length));

        //    fs.Close();

        //    string postData = "files=" + HttpUtility.UrlEncode(Convert.ToBase64String(byteFile));

        //    var webclient = new WebClient();

        //    webclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

        //    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        //    byte[] buffer = webclient.UploadData(remoteUrl, "POST", byteArray);

        //    return Encoding.UTF8.GetString(buffer);
        //}

        public static string Get(string strURL)
        {
            try
            {
                System.Net.HttpWebRequest request;
                // 创建一个HTTP请求
                request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
                request.Method = "get";
                System.Net.HttpWebResponse response;
                response = (System.Net.HttpWebResponse)request.GetResponse();
                System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string responseText = myreader.ReadToEnd();
                myreader.Close();
                return responseText;
            }catch(Exception ex){
                return "";
            }
        }

    }
}
